/*
*
* ColourManager
*
* Stores colour tables created using the giCentre colour utilities,
* and looks up colours for plotting
*
*/
class ColourManager {
  
  // ---------------------------------------
  // attributes
  // ---------------------------------------
  ColourTable[] cTables = new ColourTable[17];
  
  // ---------------------------------------
  // constructor
  // ---------------------------------------
  ColourManager() {
    
    // create a ColourTable for each drawing mode
    // colours for tables taken from colorbrewer2.org
    
    // neighbourhood display mode; leave colour table null
    cTables[0] = new ColourTable();
    
    // average age -- diverging colour set used
    cTables[1] = new ColourTable();
    cTables[1].addContinuousColourRule(0.5/6, 140, 81, 10);
    cTables[1].addContinuousColourRule(1.5/6, 216, 179, 101);
    cTables[1].addContinuousColourRule(2.5/6, 246, 232, 195);
    cTables[1].addContinuousColourRule(3.5/6, 199, 234, 229);
    cTables[1].addContinuousColourRule(4.5/6, 90, 180, 172);
    cTables[1].addContinuousColourRule(5.5/6, 1, 102, 94);
    
    // percent renters/owners -- sequential colour set used
    cTables[2] = ColourTable.getPresetColourTable(ColourTable.PU_BU, 0, 1);
    cTables[3] = ColourTable.getPresetColourTable(ColourTable.PU_BU, 0, 1);
//    cTables[2] = new ColourTable();
//    cTables[2].addContinuousColourRule(0.5/6, 237, 248, 251);
//    cTables[2].addContinuousColourRule(1.5/6, 204, 236, 230);
//    cTables[2].addContinuousColourRule(2.5/6, 153, 216, 201);
//    cTables[2].addContinuousColourRule(3.5/6, 102, 194, 164);
//    cTables[2].addContinuousColourRule(4.5/6, 44, 162, 95);
//    cTables[2].addContinuousColourRule(5.5/6, 0, 109, 44);
    
    // percent owners -- sequential colour set used
//    cTables[3] = new ColourTable();
//    cTables[3].addContinuousColourRule(0.5/6, 237, 248, 251);
//    cTables[3].addContinuousColourRule(1.5/6, 191, 211, 230);
//    cTables[3].addContinuousColourRule(2.5/6, 158, 188, 218);
//    cTables[3].addContinuousColourRule(3.5/6, 140, 150, 198);
//    cTables[3].addContinuousColourRule(4.5/6, 136, 86, 167);
//    cTables[3].addContinuousColourRule(5.5/6, 129, 15, 124);
    
    // people per dwelling -- diverging colour set used
    cTables[4] = ColourTable.getPresetColourTable(ColourTable.P_R_GN, 0, 1);
//    cTables[4] = new ColourTable();
//    cTables[4].addContinuousColourRule(0.5/6, 254, 240, 217);
//    cTables[4].addContinuousColourRule(1.5/6, 253, 212, 158);
//    cTables[4].addContinuousColourRule(2.5/6, 253, 187, 132);
//    cTables[4].addContinuousColourRule(3.5/6, 252, 141, 89);
//    cTables[4].addContinuousColourRule(4.5/6, 227, 74, 51);
//    cTables[4].addContinuousColourRule(5.5/6, 179, 0, 0);
    
    // average/median income -- diverging colour set used
    cTables[5] = ColourTable.getPresetColourTable(ColourTable.PI_Y_G, 0, 1);
    cTables[6] = ColourTable.getPresetColourTable(ColourTable.PI_Y_G, 0, 1);
    
    // total number of structures -- diverging colour set used
    cTables[7] = ColourTable.getPresetColourTable(ColourTable.PU_OR, 0, 1);
    
    // percentage of various types of structures -- sequential color set used
    cTables[8] = ColourTable.getPresetColourTable(ColourTable.REDS, 0, 1);
    cTables[9] = ColourTable.getPresetColourTable(ColourTable.REDS, 0, 1);
    cTables[10] = ColourTable.getPresetColourTable(ColourTable.REDS, 0, 1);
    cTables[11] = ColourTable.getPresetColourTable(ColourTable.REDS, 0, 1);
    
    // usage status of various types of structures -- sequential color set used
    cTables[12] = ColourTable.getPresetColourTable(ColourTable.PU_OR, 0, 1);
    cTables[13] = ColourTable.getPresetColourTable(ColourTable.PU_OR, 0, 1);
    cTables[14] = ColourTable.getPresetColourTable(ColourTable.PU_OR, 0, 1);
    cTables[15] = ColourTable.getPresetColourTable(ColourTable.PU_OR, 0, 1);
    cTables[16] = ColourTable.getPresetColourTable(ColourTable.PU_OR, 0, 1);
    
  } // constructor
  
  // -------------------------------------
  // getColour
  // takes min, max, and value, and returns colour
  // -------------------------------------
  color getColour(int dMode, float mi, float ma, float val) {
    
    // calculate interpolated index of value
    float ind = (val - mi) / (ma - mi);
    
    // lookup colour from colour tables
    color out = cTables[dMode].findColour(ind);
    
    // return colour
    return out;
    
  } // getColour
  
} // ColourManager
